import 'package:sl_fast_dev/sl_fast_dev.dart';
import 'package:sl_fast_dev/src/dao/sl_node.dart';
import 'package:sl_fast_dev/src/utils/sl_consts.dart';

class SLContainer {
  List<SLNode> headers;

  List<String> protocal;
  String date;

  final SLNode node;
  SLContainer(this.node) {
    headers = <SLNode>[];
    protocal = <String>[];

    date =
        '${DateTime.now().year}-${DateTime.now().month}-${DateTime.now().day}';
  }

  /// 获取所有需要导入的头文件
  SLContainer getAllHeaders() {
    headers = <SLNode>[];

    if (!node.hasChildren()) return this;

    node.children.forEach((child) {
      if (!child.hasChildren()) return;

      if (child.isContainer()) {
        headers.addAll(child.getAllUITableViewCells());
        //headers.addAll(child.getAllUIScrollViewSubViews());
      } else {
        headers.add(child);
      }
    });

    return this;
  }

  List<String> getAllHeadersStringL() {
    getAllHeaders();

    var hi = <String>[];

    if (node.nodeFor != SLNodeFor.SLNodeForVM) {
      if (node.isCreateVM() && SLFastDevConfig().hasVM) {
        hi.add(node.viewModel());
      }
    }

    headers.forEach((header) {
      hi.add(header.nodeFor == SLNodeFor.SLNodeForVM
          ? header.viewModel()
          : header.cls());
    });

    return hi;
  }

  SLContainer getAllProtocal() {
    if (!node.hasChildren()) return this;

    node.children.forEach((child) {
      if (child.isUITableView()) {
        if (!protocal.contains(TableViewDataSource)) {
          protocal.add(TableViewDataSource);
        }
        if (!protocal.contains(UITableViewDelegate)) {
          protocal.add(UITableViewDelegate);
        }
      }
    });

    return this;
  }
}
